package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.AppMenu;
import com.example.rbacmanage.entity.system.DictData;
import com.example.rbacmanage.entity.system.DictType;
import com.example.rbacmanage.service.app.AppMenuService;
import com.example.rbacmanage.service.system.DictDataService;
import com.example.rbacmanage.service.system.DictTypeService;
import com.example.rbacmanage.vo.MenuTreeResp;
import com.example.rbacmanage.vo.MenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/background/appmenu")
public class AppMenuController {
    @Autowired
    private AppMenuService appMenuService;


    @GetMapping("/page")
    public Result page(AppMenu appMenu){
        return Result.success(appMenuService.getPage(appMenu));
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(appMenuService.getById(id));
    }

    @GetMapping("/list")
    public Result list(AppMenu appMenu){
        return Result.success(appMenuService.getAll(appMenu));
    }

    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('background:appmenu:add')")
    public Result add(@RequestBody AppMenu appMenu){
        appMenuService.save(appMenu);
        return Result.success();
    }

    @PutMapping("/update")
    @PreAuthorize("hasAnyAuthority('background:appmenu:update')")
    public Result update(@RequestBody AppMenu appMenu){
        appMenuService.update(appMenu);
        return Result.success();
    }

    @DeleteMapping("/remove")
    @PreAuthorize("hasAnyAuthority('background:appmenu:remove')")
    public Result remove(@RequestBody Long[] ids){
        appMenuService.remove(ids);
        return Result.success();
    }
}
